exutils = require("express/lib/utils")
utils = require("./utils")
fs = require("fs")
querystring = require 'querystring'
request = require "request"
uuid = require "node-uuid"
redis = require "redis"


client = redis.createClient()

connect = module.exports = (app)->
  app.get "/connect/qplus/", (req, res)->
    dd = req.query
    osig = dd.sig
    console.log dd
    #dd.app_nonce = uuid.v1()[..20]
    delete dd.sig
    #console.log utils.hmac_sha1 querystring.stringify(dd), "eDrz06B9AbWeRthK&", osig
    n = '' + ((new Date).getTime() | 0)
    dd.app_ts = n
    dd.app_userip = req.ip()
    #console.log dd
    dd.sig = utils.hmac_sha1(querystring.stringify(dd), "eDrz06B9AbWeRthK&").toUpperCase()

    #console.log querystring.stringify dd
    #request {url:'http://openid.qplus.com/cgi-bin/app_get_userinfo', method:'POST', body: querystring.stringify(dd)}, (err, ret)->
      #console.log err, ret.body
    res.render "connect/qplus"

  app.get "/connect/qplus/ed/", (req, res)->
    res.render "connect/qplus_ed"


